package com.wc.codeforces.DP.数位DP.Vlad_and_a_Sum_of_Sum_of_Digits;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/7/5 11:28
 * @description https://codeforces.com/problemset/problem/1926/C
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 10;
    static int[] num = new int[N];
    static int[] base = new int[N];
    static int n;

    public static void main(String[] args) {
        int T = sc.nextInt();
        for (int i = 0, j = 1; i < N; i++, j *= 10) {
            base[i] = j;
        }
        while (T-- > 0) {
            n = sc.nextInt();
            out.println(dp(n));
        }
        out.flush();
    }

    static int dp(int n) {
        int len = 0;
        int u = n;
        while (u > 0) {
            num[++len] = u % 10;
            u /= 10;
        }
        int res = 0;
        int last = 0;
        for (int i = len; i >= 1; i--) {
            int x = num[i];
            // last = 0 ~ abc - 1
            res += last * 45 * base[i - 1];
            // last = abc x = 0 ~ x - 1
            res += (x - 1) * x / 2 * base[i - 1];
            // x = x
            res += x * (n % base[i - 1] + 1);
            last = last * 10 + x;
        }

        return res;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
